package com.example.pinkcat.activity.api.getData;

import android.annotation.SuppressLint;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.pinkcat.R;
import com.example.pinkcat.activity.adapter.FFP_recyleview_adapter;
import com.example.pinkcat.activity.adapter.SP_recyleview_adapter;
import com.example.pinkcat.activity.adapter.U_recyleview_adapter;
import com.example.pinkcat.activity.adapter.VAMF_recyleview_adapter;
import com.example.pinkcat.activity.adapter.VP1_recyleview_adapter;
import com.example.pinkcat.activity.adapter.VP1_recyleview_adapter_underrecycle;
import com.example.pinkcat.activity.adapter.VP2_recyleview_adapter;
import com.example.pinkcat.activity.adapter.V_recyleview_adapter;
import com.example.pinkcat.activity.api.ApiService;
import com.example.pinkcat.activity.api.entity.ResponsEntity_PinkCatApp;
import com.example.pinkcat.activity.api.entity.ResponsEntity_boolean;
import com.example.pinkcat.activity.api.entity.ResponsEntity_comment;
import com.example.pinkcat.activity.api.entity.ResponsEntity_tvlist;
import com.example.pinkcat.activity.api.entity.ResponsEntity_user;
import com.example.pinkcat.activity.api.entity.ResponsEntity_userpageinfo;
import com.example.pinkcat.activity.api.entity.ResponsEntity_video;
import com.example.pinkcat.activity.api.entity.ResponsEntity_videoinfo;
import com.example.pinkcat.activity.api.entity.ResponsEntity_vipinfo;
import com.example.pinkcat.activity.api.entity.VideoEntity;
import com.example.pinkcat.activity.pinkCatUser.userStaticMsg;
import com.example.pinkcat.api.ApiServer;
import com.example.pinkcat.api.entity.FanKeepStaticMsg;
import com.example.pinkcat.api.entity.ResponsEntity_Myfanentity;
import com.example.pinkcat.api.entity.ResponsEntity_fankeep;
import com.example.pinkcat.client.Client;
import com.google.gson.Gson;
import com.rishabhharit.roundedimageview.RoundedImageView;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

public class GetData<T> {
    static String uri="http://119.91.218.197:8888/";
    // static String uri="http://4218.197:8089/";


    //登陆
    public static boolean longin(String phone, String mail,String password, Context context,boolean iscode) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (password==null)
            return false;
        System.out.println(password+password.length());
        if (isPhone(phone)){
            if (iscode) {
                userStaticMsg.style="phonecode";
                call = apiService.login(phone, password, "phonecode","on");//发送登陆请求
            }
            else {
                userStaticMsg.style="phonepassword";
                call = apiService.login(phone, password, "phonepassword","on");//发送登陆请求
            }
        }
        else  if (isMail(mail)){
                if (iscode){
                    userStaticMsg.style="emailcode";call = apiService.login(mail,password,"emailcode","on");//发送登陆请求
                }

            else
                {
                    userStaticMsg.style="emailpassword";call = apiService.login(mail,password,"emailpassword","on");//发送登陆请求
                }

        }
        else {
            Toast.makeText(context, "手机或邮箱格式不正确", Toast.LENGTH_SHORT).show();
            return false;
        }


        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            String jsonStr=responseBody.string();
            Gson gson=new Gson();
            ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
            System.out.println(responseBody.string());
            if (ra.getCode()==200){
                userStaticMsg.login=true;
                userStaticMsg.phone=phone;
                userStaticMsg.mail=mail;
                return true;
            }

            else {
                Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                return false;
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //注册
    public static boolean register(String phone, String verification, String password, Context context) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (isPhone(phone))
            call = apiService.register(phone,verification,password);//发送登陆请求
        else{
            Toast.makeText(context,"手机格式不正确",Toast.LENGTH_SHORT).show();
            return false;
        }

        System.out.println(phone+verification+password);
        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            if (responseBody==null){
                Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse",response.body().toString());
                //转化json字符串
                String jsonStr=responseBody.string();
                Gson gson= new Gson();
                ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                System.out.println(ra.getCode()+"dssfsdfsdfs");
                if (ra.getCode()==200){
                    Toast.makeText(context,"注册成功",Toast.LENGTH_SHORT).show();
                    return true;
                }
                else {
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //更改密码
    public static boolean changePassword(String phone, String verification, String password, Context context) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (isPhone(phone))
            call = apiService.changePassword(phone,verification,password);//
        else{
                Toast.makeText(context,"手机号不正确",Toast.LENGTH_SHORT).show();
                return false;
        }

        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            if (responseBody==null){
                Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse",response.body().toString());
                //转化json字符串
                String jsonStr=responseBody.string();
                Gson gson= new Gson();
                ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getData()){
                    Toast.makeText(context,"更改成功",Toast.LENGTH_SHORT).show();
                    return true;
                }
                else {
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //获取验证码
    public static void getVerification(String phone, String mail,Context context) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (isMail(mail))
            call = apiService.getVerification_byemail(mail);//发送登陆请求
        else if (isPhone(phone))
            call = apiService.getVerification_byphone(phone);//发送登陆请求
        else{
            Toast.makeText(context,"输入格式不正确.",Toast.LENGTH_SHORT).show();
            return;
        }


        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    Gson gson= new Gson();
                    ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    Toast.makeText(context,"已发送验证码",Toast.LENGTH_SHORT).show();
//                    if (ra.entity){
//                        Toast.makeText(context,"已发送验证码",Toast.LENGTH_SHORT).show();
//                    }
//                    else {
//                        switch (ra.code){
//                            case 402:Toast.makeText(context,"用户不存在",Toast.LENGTH_SHORT).show();
//                        }
//                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }

    //获取最新app
    public static boolean getPinkCat(Context context) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        call = apiService.getPinkCat();//发送登陆请求

        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            if (responseBody==null){
                Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse",response.body().toString());
                //转化json字符串
                String jsonStr=responseBody.string();
                Gson gson= new Gson();
                ResponsEntity_PinkCatApp ra=gson.fromJson(jsonStr, ResponsEntity_PinkCatApp.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getData().version!=null&& ra.getData().url!=null){
                    String version=ra.getData().version;
                    String url=ra.getData().url;
                    userStaticMsg.appVersion=version;
                    userStaticMsg.appUrl=url;
                    return true;
                }
                else {
                    return false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //提交反馈
    public static boolean suggest(String type, String suggest, String mail, Context context) {

        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (isMail(mail)){
            System.out.println(mail+"efaufheauhfaehfaf");
            call = apiService.suggest(userStaticMsg.userId,userStaticMsg.userName,type,suggest,mail);//发送登陆请求
        }
        else {
            Toast.makeText(context,"邮箱格式不正确",Toast.LENGTH_SHORT).show();
            return false;
        }

        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            if (responseBody==null){
                Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse",response.body().toString());
                //转化json字符串
                String jsonStr=responseBody.string();
                Gson gson= new Gson();
                ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getData()){
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return true;
                }
                else {
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //用户信息只有用户未登录才会返回true
    public static boolean get_setUserInfo(Context context, ImageView head, TextView name, TextView sex, TextView birth, TextView area, TextView school, TextView pcid, TextView phone, TextView mail) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (isMail(userStaticMsg.mail))
            call = apiService.getUserInfo(userStaticMsg.mail,"mail");//发送登陆请求
        else if (isPhone(userStaticMsg.phone))
            call = apiService.getUserInfo(userStaticMsg.phone,"phone");//发送登陆请求
        else{
            Toast.makeText(context,"请先登陆到PinkCat",Toast.LENGTH_SHORT).show();
            return true;
        }

        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            if (responseBody==null){
                Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse",response.body().toString());
                //转化json字符串
                String jsonStr=responseBody.string();
                Gson gson= new Gson();
                ResponsEntity_user ra=gson.fromJson(jsonStr, ResponsEntity_user.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getData()==null){
                    Toast.makeText(context,"没有用户信息",Toast.LENGTH_SHORT).show();
                    return false;
                }
                if (ra.getData().getArea()==null||ra.getData().getDate_birth()==null||ra.getData().getHead_photo()==null||ra.getData().getEmail()==null||ra.getData().getPhone_num()==null||ra.getData().getSchool()==null||ra.getData().getSex()==null||ra.getData().getUser_name()==null){
                    Toast.makeText(context,"还可以完善信息:)",Toast.LENGTH_SHORT).show();
                    if (ra.getData().getHead_photo()!=null){
                        Glide.with(context).load(Uri.parse(ra.getData().getHead_photo())).into(head);//图片
                    }
                    if (ra.getData().getUser_name()!=null){
                        name.setText(ra.getData().getUser_name());
                    }
                    if (ra.getData().getSex()!=null){
                        sex.setText(ra.getData().getSex());
                    }
                    if (ra.getData().getDate_birth()!=null){
                        SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd");
                        birth.setText(format.format(ra.getData().getDate_birth()));
                    }
                    if (ra.getData().getArea()!=null){
                        area.setText(ra.getData().getArea());
                    }
                    if (ra.getData().getSchool()!=null){
                        school.setText(ra.getData().getSchool());
                    }
                    if (ra.getData().getUser_id()!=null){
                        pcid.setText(ra.getData().getUser_id());
                    }
                    if (ra.getData().getPhone_num()!=null){
                        phone.setText(ra.getData().getPhone_num());
                    }
                    if (ra.getData().getEmail()!=null){
                        mail.setText(ra.getData().getEmail());
                    }
                }
                else {
                    if (ra.getData().getHead_photo()!=null){
                        Glide.with(context).load(Uri.parse(ra.getData().getHead_photo())).into(head);//图片
                    }
                    if (ra.getData().getUser_name()!=null){
                        name.setText(ra.getData().getUser_name());
                    }
                    if (ra.getData().getSex()!=null){
                        sex.setText(ra.getData().getSex());
                    }
                    if (ra.getData().getDate_birth()!=null){
                        SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd");
                        birth.setText(format.format(ra.getData().getDate_birth()));
                    }
                    if (ra.getData().getArea()!=null){
                        area.setText(ra.getData().getArea());
                    }
                    if (ra.getData().getSchool()!=null){
                        school.setText(ra.getData().getSchool());
                    }
                    if (ra.getData().getUser_id()!=null){
                        pcid.setText(ra.getData().getUser_id());
                    }
                    if (ra.getData().getPhone_num()!=null){
                        phone.setText(ra.getData().getPhone_num());
                    }
                    if (ra.getData().getEmail()!=null){
                        mail.setText(ra.getData().getEmail());
                    }
                    return false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }


    //根据标签获取相关视频
    public static void getSameVideo(String labs,String video_id, Context context, VP1_recyleview_adapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        call = apiService.getvideo(labs,video_id);


        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    Gson gson= new Gson();
                    ResponsEntity_video ra=gson.fromJson(jsonStr, ResponsEntity_video.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    adapter.setxiangguanData(ra.getData());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }


    //根据标签获取相关视频
    public static void getSameVideo1(String labs,String video_id, Context context, V_recyleview_adapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        call = apiService.getvideo(labs,video_id);


        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    System.out.println(jsonStr);
                    Gson gson= new Gson();
                    ResponsEntity_video ra=gson.fromJson(jsonStr, ResponsEntity_video.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    adapter.setvideolistData(ra.getData());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }


    //判断邮箱格式
    public static boolean isMail(String str) {
        String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern p;
        Matcher m;
        p = Pattern.compile(regEx1);
        m = p.matcher(str);
        if(m.matches())
            return true;
        else
            return false;
    }

    //判断手机号11位格式
    public static boolean isPhone(String str) {
        String regEx1 = "[0-9]{11}$";
        Pattern p;
        Matcher m;
        p = Pattern.compile(regEx1);
        m = p.matcher(str);
        if(m.matches())
            return true;
        else
            return false;
    }

    /**
     * @return****/
//获取用户信息
    public static void getUserinfo(Context context) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (isMail(userStaticMsg.mail)){
            call = apiService.getUserInfo(userStaticMsg.mail,"email");//发送登陆请求
        }
        else if (isPhone(userStaticMsg.phone)){
            call = apiService.getUserInfo(userStaticMsg.phone,"phone");//发送登陆请求

        }
        else {
//            Toast.makeText(context,"未登录",Toast.LENGTH_SHORT).show();
            return;
        }


        //同步请求
            try {
                Response<ResponseBody> response=call.execute();
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return ;
                }
                Log.e("onResponse",response.body().toString());
                //转化json字符串
                String jsonStr=responseBody.string();
                Gson gson= new Gson();
                ResponsEntity_user ra=gson.fromJson(jsonStr, ResponsEntity_user.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getCode()==200){
                    userStaticMsg.userId=ra.getData().getUser_id();
                    userStaticMsg.userName=ra.getData().getUser_name();
                    userStaticMsg.phone=ra.getData().getPhone_num();
                    userStaticMsg.mail=ra.getData().getEmail();
                    userStaticMsg.head_img=ra.getData().getHead_photo();
                    userStaticMsg.vip=ra.getData().getMember();
                    userStaticMsg.password=ra.getData().getUser_pass();
                    return ;
                }
                else {
                    return ;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
    }


    //获取验证码
    public static void gettuijianvideo(Context context) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (userStaticMsg.userId!="-1")
            call = apiService.getvideobyid(userStaticMsg.userId);//发送登陆请求
        else{
            Toast.makeText(context,"请登录",Toast.LENGTH_SHORT).show();
            return;
        }


        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    Gson gson= new Gson();
                    ResponsEntity_video ra=gson.fromJson(jsonStr, ResponsEntity_video.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getData().size()>0){
                        ra.getData();

                    }
                    else {
//                        Toast.makeText(context,"没有数据",Toast.LENGTH_SHORT).show();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }

    //修改用户信息
    public static boolean updateMsg(String msg, String type, Context context){
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (userStaticMsg.userId.equals("-1")){
            Toast.makeText(context,"登陆状态异常",Toast.LENGTH_SHORT).show();
            return false;
        }
        switch(type){
            case "name":call = apiService.updateusername(userStaticMsg.userId, msg);break;
            case "sex":call = apiService.updatesex(userStaticMsg.userId, msg);break;
            case "birth":call = apiService.updatebirthday(userStaticMsg.userId, msg);break;
            case "area":call = apiService.updatearea(userStaticMsg.userId, msg);break;
            case "school":call = apiService.updateschool(userStaticMsg.userId, msg);break;
            default:Toast.makeText(context,"修改类型未知",Toast.LENGTH_SHORT).show();return false;
        }
        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            if (responseBody==null){
                Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse",response.body().toString());
                //转化json字符串
                String jsonStr=responseBody.string();
                Gson gson= new Gson();
                System.out.println(jsonStr);
                ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getData()){
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return true;
                }
                else {
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }
    //修改用户头像信息
    public static boolean updateHead(String file_path, Context context){
        //协议内容
        System.out.println(file_path+"文件路径sssssss");
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        if (userStaticMsg.userId.equals("-1")){
            Toast.makeText(context,"登陆状态异常",Toast.LENGTH_SHORT).show();
            return false;
        }
        /**/
        File file = new File(file_path);
        RequestBody fileRQ = RequestBody.create(MediaType.parse("image/*"), file);
        MultipartBody.Part part= MultipartBody.Part.createFormData("file", file.getName(), fileRQ);
        /**/
        Call<ResponseBody> call;
            call = apiService.updateshead(userStaticMsg.userId, part);

        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            if (responseBody==null){
                Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse",response.body().toString());
                //转化json字符串
                String jsonStr=responseBody.string();
                Gson gson= new Gson();
                System.out.println(jsonStr);
                ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getData()){
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return true;
                }
                else {
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }
    //修改绑定邮箱
    public static boolean bindemail(String email, String code, Context context) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (userStaticMsg.userId.equals("-1"))
        {
            Toast.makeText(context,"登陆异常",Toast.LENGTH_SHORT).show();
            return false;
        }
        if (isMail(email)){
            if (code.length()<2){
                Toast.makeText(context,"验证码异常",Toast.LENGTH_SHORT).show();
                return false;
            }
            call = apiService.bindemail(userStaticMsg.userId,email,code);//发送登陆请求
        }
        else {
            Toast.makeText(context, "邮箱格式不正确", Toast.LENGTH_SHORT).show();
            return false;
        }


        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            String jsonStr=responseBody.string();
            Gson gson=new Gson();
            ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
            System.out.println(responseBody.string());
            if (ra.getCode()==200){
                Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                userStaticMsg.mail=email;
                return true;
            }

            else {
                Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                return false;
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //获取vip信息
    @SuppressLint("SetTextI18n")
    public static boolean getvipinfo(Context context, RoundedImageView head, TextView name, TextView isvip, TextView startvip, TextView endvip, View viplayout) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (userStaticMsg.userId.equals("-1"))
        {
            Toast.makeText(context,"登陆异常",Toast.LENGTH_SHORT).show();
            return false;
        }
        call = apiService.getvipinfo(userStaticMsg.userId);
        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            String jsonStr=responseBody.string();
            Gson gson=new Gson();
            ResponsEntity_vipinfo ra=gson.fromJson(jsonStr, ResponsEntity_vipinfo.class); //把响应数据jsonstr转化为ServiceBobdy实体类
            System.out.println(responseBody.string());
            if (ra.getCode()==200){
                Glide.with(context).load(ra.getData().headlink).into(head);
                name.setText(ra.getData().username);
                if (ra.getData().isvip){
                    isvip.setText("PinkCat大会员");
                    viplayout.setBackground(context.getResources().getDrawable(R.drawable.backgroud_cycle_pink_whit));
                }
                else{
                    isvip.setText("你目前不是大会员");
                    viplayout.setBackground(context.getResources().getDrawable(R.drawable.backgroud_cycle_grey_whit));
                }
                startvip.setText("开通时间"+ra.getData().startvip);
                endvip.setText("到期时间"+ra.getData().endtvip);
                return true;
            }

            else {
                Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                return false;
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //获取vip申请
    @SuppressLint("SetTextI18n")
    public static boolean getvip(Context context,String vip_type) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (userStaticMsg.userId.equals("-1"))
        {
            Toast.makeText(context,"登陆异常",Toast.LENGTH_SHORT).show();
            return false;
        }
        call = apiService.getvip(userStaticMsg.userId,vip_type);
        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            String jsonStr=responseBody.string();
            Gson gson=new Gson();
            ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
            System.out.println(responseBody.string());
            if (ra.getCode()==200){
               Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                return true;
            }

            else {
                Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                return false;
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //获取我发布的视频
    public static void getMyVideo(Context context, U_recyleview_adapter adapter,boolean ismyvideonotmyfollow,String user_id) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (user_id.equals("-1"))
        {
            Toast.makeText(context,"登陆异常",Toast.LENGTH_SHORT).show();
            return ;
        }
        if (ismyvideonotmyfollow)
            call = apiService.getmyvideo(user_id);
        else
            call = apiService.getmyfollowvideo(user_id);

        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    Gson gson= new Gson();
                    ResponsEntity_video ra=gson.fromJson(jsonStr, ResponsEntity_video.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200){
                        //按时间排序
                        Collections.sort(ra.getData(), new Comparator<VideoEntity>() {
                            public int compare(VideoEntity o1, VideoEntity o2) {

                                return o2.getVideo_pub_time().compareTo(o1.getVideo_pub_time());
                            }
                        });
                        adapter.setData(ra.getData());
                    }
                    else {
                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }

    //获取用户页面用户信息
    @SuppressLint("SetTextI18n")
    public static void getuserpageuserinfo(String user_id,Context context, RoundedImageView head, TextView name, TextView target,TextView followbtn) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (user_id.equals("-1"))
        {
            Toast.makeText(context,"登陆异常",Toast.LENGTH_SHORT).show();
            return ;
        }
        call = apiService.getuserpageinfo(user_id,userStaticMsg.userId);
        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            String jsonStr=responseBody.string();
            Gson gson=new Gson();
            ResponsEntity_userpageinfo ra=gson.fromJson(jsonStr, ResponsEntity_userpageinfo.class); //把响应数据jsonstr转化为ServiceBobdy实体类
            if (ra.getCode()==200){
                Glide.with(context).load(Uri.parse(ra.getData().getHead_photo())).into(head);
                name.setText(ra.getData().getUser_name());
                if (ra.getData().isIsvip()){
                    target.setEnabled(true);
                    name.setTextColor(context.getResources().getColor(R.color.black));
                }
                else{
                    target.setEnabled(false);
                    name.setTextColor(context.getResources().getColor(R.color.black));
                }
                if (ra.getData().isIskeep()){
                    followbtn.setText(R.string.unfollow);
                    followbtn.setTextColor(context.getResources().getColor(R.color.black_overlay));
                    followbtn.setBackground(context.getResources().getDrawable(R.drawable.backgroud_cycle_grey));
                }else {
                    followbtn.setText(R.string.follow);
                    followbtn.setTextColor(context.getResources().getColor(R.color.white));
                    followbtn.setBackground(context.getResources().getDrawable(R.drawable.backgroud_cycle_pink));
                }
                return ;
            }

            else {
                Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                return ;
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return ;
    }

    //获取关注粉丝列表
    public static void  getFollowOrFansUser(Context context, FFP_recyleview_adapter adapter, boolean ismyfollow, String user_id) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (user_id.equals("-1"))
        {
            Toast.makeText(context,"未登录",Toast.LENGTH_SHORT).show();
            return ;
        }
        if (ismyfollow)
            call = apiService.getmyfollows(user_id);
        else
            call = apiService.getmyfans(user_id);

        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    System.out.println(jsonStr);
                    Gson gson= new Gson();
                    ResponsEntity_Myfanentity ra=gson.fromJson(jsonStr, ResponsEntity_Myfanentity.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200){
                        adapter.setData(ra.getData());
                    }
                    else {
                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }

    //关注与取关
    @SuppressLint("SetTextI18n")
    public static boolean followOrUnfollow(Context context,String follow_id,boolean isfollowrequst) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (userStaticMsg.userId.equals("-1"))
        {
            Toast.makeText(context,"未登录",Toast.LENGTH_SHORT).show();
            return false;
        }
        if (isfollowrequst)
            call = apiService.follow(userStaticMsg.userId,follow_id);
        else
            call = apiService.unfollow(userStaticMsg.userId,follow_id);
        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            String jsonStr=responseBody.string();
            Gson gson=new Gson();
            ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
            System.out.println(responseBody.string());
            if (ra.getCode()==200){
                Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                return true;
            }

            else {
                Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                return false;
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //搜索粉丝/关注
    @SuppressLint("SetTextI18n")
    public static void searchfanorfollow(Context context, String searchtxt, boolean issearchfollow, FFP_recyleview_adapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (userStaticMsg.userId.equals("-1"))
        {
            Toast.makeText(context,"登陆异常",Toast.LENGTH_SHORT).show();
            return ;
        }
        if (issearchfollow)
            call = apiService.searchfollow(userStaticMsg.userId,searchtxt);
        else
            call = apiService.searchfans(userStaticMsg.userId,searchtxt);
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    System.out.println(jsonStr);
                    Gson gson= new Gson();
                    ResponsEntity_Myfanentity ra=gson.fromJson(jsonStr, ResponsEntity_Myfanentity.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200){
                        //Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                        adapter.setData(ra.getData());
                    }
                    else {
                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }

    //获取播放视频信息
    @SuppressLint("SetTextI18n")
    public static void getVideoinfo(Context context,String video_id,V_recyleview_adapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        call = apiService.getpalyvideo(video_id,userStaticMsg.userId);
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    System.out.println(jsonStr);
                    Gson gson= new Gson();
                    ResponsEntity_videoinfo ra=gson.fromJson(jsonStr, ResponsEntity_videoinfo.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200){
                        //Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                        adapter.setvideoinfoData(ra.getData());
                    }
                    else {
                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }

    //获取播放视频信息
    @SuppressLint("SetTextI18n")
    public static void getVideoinfo1(Context context,String video_id,VP1_recyleview_adapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        call = apiService.getpalyvideo(video_id,userStaticMsg.userId);
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    System.out.println(jsonStr);
                    Gson gson= new Gson();
                    ResponsEntity_videoinfo ra=gson.fromJson(jsonStr, ResponsEntity_videoinfo.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200){
                        //Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                        adapter.setvideoinfoData(ra.getData());
                    }
                    else {
                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }

    //关注与取关
    @SuppressLint("SetTextI18n")
    public static boolean video_like_follow_un(Context context,String video_id,String clikeType) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (userStaticMsg.userId.equals("-1"))
        {
            Toast.makeText(context,"登陆异常",Toast.LENGTH_SHORT).show();
            return false;
        }
        switch (clikeType){
            case "like":call = apiService.likevideo(userStaticMsg.userId,video_id);break;
            case "unlike":call = apiService.unlickvideo(userStaticMsg.userId,video_id);break;
            case "follow":call = apiService.followvideo(userStaticMsg.userId,video_id);break;
            case "unfollow":call = apiService.unfollowvideo(userStaticMsg.userId,video_id);break;
            default:Toast.makeText(context,"未知操作",Toast.LENGTH_SHORT).show();return false;
        }
        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            String jsonStr=responseBody.string();
            Gson gson=new Gson();
            ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
            System.out.println(responseBody.string());
            if (ra.getCode() ==200){
                Toast.makeText(context,"-v-",Toast.LENGTH_SHORT).show();
                return true;
            }

            else {
                Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                return false;
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //获取视频评论信息
    @SuppressLint("SetTextI18n")
    public static void getVideoComment(Context context,String video_id,V_recyleview_adapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        call = apiService.getcomment(video_id);
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    System.out.println(jsonStr+"评论评论评论");
                    Gson gson= new Gson();
                    ResponsEntity_comment ra=gson.fromJson(jsonStr, ResponsEntity_comment.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200){
                        //Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                        adapter.setcomentlistData(ra.getData());
                    }
                    else {
                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }
    //获取视频评论信息
    @SuppressLint("SetTextI18n")
    public static void getVideoComment2(Context context, String video_id, VP2_recyleview_adapter adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        call = apiService.getcomment(video_id);
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    System.out.println(jsonStr+"评论评论评论");
                    Gson gson= new Gson();
                    ResponsEntity_comment ra=gson.fromJson(jsonStr, ResponsEntity_comment.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200){
                        //Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                        adapter.setcomentlistData(ra.getData());
                    }
                    else {
                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }

    //获取tv集数连接
    @SuppressLint("SetTextI18n")
    public static void gettvlistvyid(Context context, String video_id, VP1_recyleview_adapter_underrecycle adapter) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        call = apiService.gettvlistbyid(video_id);
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    Gson gson= new Gson();
                    ResponsEntity_tvlist ra=gson.fromJson(jsonStr, ResponsEntity_tvlist.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200){
                        //Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                        adapter.setTvlist(ra.getData());
                    }
                    else {
                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }

    //上传视频
    public static boolean sendVideo(String videopath,String videofacepath,String editTitle,String video_type,String editvideolabs,String videointroduction,Context context){
        //协议内容
        System.out.println(videopath+"文件路径sssssss");
        System.out.println(videofacepath+"文件路径sssssss");
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        if (userStaticMsg.userId.equals("-1")){
            Toast.makeText(context,"登陆状态异常",Toast.LENGTH_SHORT).show();
            return false;
        }
        /**/
        File videofile = new File(videopath);
        File videofacefile = new File(videofacepath);
        RequestBody fileRQ_video = RequestBody.create(MediaType.parse("file/*"), videofile);
        RequestBody fileRQ_img = RequestBody.create(MediaType.parse("image/*"), videofacefile);
        MultipartBody.Part part_image= MultipartBody.Part.createFormData("image", videofacefile.getName(), fileRQ_img);
        MultipartBody.Part part_file= MultipartBody.Part.createFormData("file", videofile.getName(), fileRQ_video);
        /**/
        Call<ResponseBody> call;
        call = apiService.uploadvideo(part_file,part_image,userStaticMsg.userId,editTitle,editvideolabs,"1",video_type,videointroduction);

        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            if (responseBody==null){
                Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse",response.body().toString());
                //转化json字符串
                String jsonStr=responseBody.string();
                Gson gson= new Gson();
                System.out.println(jsonStr);
                ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getData()){
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return true;
                }
                else {
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //评论
    public static boolean sendvideo_pl(String video_id,String pltxt,Context context){
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        if (userStaticMsg.userId.equals("-1")){
            Toast.makeText(context,"登陆状态异常",Toast.LENGTH_SHORT).show();
            return false;
        }
        /**/
        /**/
        Call<ResponseBody> call;
        call = apiService.sendcomment(video_id,userStaticMsg.userId,pltxt);

        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            if (responseBody==null){
                Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse",response.body().toString());
                //转化json字符串
                String jsonStr=responseBody.string();
                Gson gson= new Gson();
                System.out.println(jsonStr);
                ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getData()){
                    //Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return true;
                }
                else {
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    //增加视频播放量
    @SuppressLint("SetTextI18n")
    public static void addplaynum(Context context, String video_id) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        call = apiService.addplaynum(video_id);
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    Gson gson= new Gson();
                    ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200){
                        //Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }
                    else {
                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }

    //点赞评论/点踩评论
    @SuppressLint("SetTextI18n")
    public static void thumbOrUnthumbpl(Context context, String comment_id,boolean isthumb) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (isthumb)
            call = apiService.thumbpl(comment_id);
        else
            call = apiService.unthumbpl(comment_id);
        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    Gson gson= new Gson();
                    ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200){
                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }
                    else {
                        Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }

    //举报评论
    public static boolean reportpl(Context context,String comment_id,String comment_message,String reporttxt){
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        if (userStaticMsg.userId.equals("-1")){
            Toast.makeText(context,"登陆状态异常",Toast.LENGTH_SHORT).show();
            return false;
        }
        Call<ResponseBody> call;
        call = apiService.reportcomment(userStaticMsg.userId,userStaticMsg.userName,comment_message,reporttxt,comment_id);

        //同步请求
        try {
            Response<ResponseBody> response=call.execute();
            ResponseBody responseBody =response.body();
            if (responseBody==null){
                Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                return false;
            }
            try {
                Log.e("onResponse",response.body().toString());
                //转化json字符串
                String jsonStr=responseBody.string();
                Gson gson= new Gson();
                System.out.println(jsonStr);
                ResponsEntity_boolean ra=gson.fromJson(jsonStr, ResponsEntity_boolean.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                if (ra.getData()){
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return true;
                }
                else {
                    Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    return false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
        }
        return false;
    }


    //搜索
    @SuppressLint("SetTextI18n")
    public static void search(Context context, String search, ArrayList<SP_recyleview_adapter> adapters) {
        //协议内容
        for (int i=0;i<adapters.size();i++){
            Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
            ApiService apiService =retrofit.create((ApiService.class));
            Call<ResponseBody> call=null;
            System.out.println(i);
            SP_recyleview_adapter adapter=adapters.get(i);
            int position=i;
            switch(i){
                case 0:call = apiService.videosearch(search);break;
                case 1:call = apiService.searchtv(search, 1);break;
                case 2:call = apiService.searchtv(search, 2);break;
                case 3:call = apiService.searchtv(search, 3);break;
                case 4:call = apiService.searchfilm(search);break;
                case 5:call = apiService.searchuser(search, userStaticMsg.userId);break;
                default:Toast.makeText(context,"搜搜类型未知",Toast.LENGTH_SHORT).show();return;
            }
            //异步请求
            if (call!=null){
                call.enqueue(new Callback<ResponseBody>() {
                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        ResponseBody responseBody =response.body();
                        if (responseBody==null){
                            Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                            return;
                        }
                        try {
                            Log.e("onResponse",response.body().toString());
                            //转化json字符串
                            String jsonStr=responseBody.string();
                            Gson gson= new Gson();
                            System.out.println(jsonStr+"position=="+position);
                            ResponsEntity_Myfanentity ra=gson.fromJson(jsonStr, ResponsEntity_Myfanentity.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                            if (ra.getCode()==200){

                                //Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                                adapter.setData(jsonStr,position);
                            }
                            else {
                                Toast.makeText(context,"已经没有更多了",Toast.LENGTH_SHORT).show();
                            }

                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {
                        Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
                    }
                });
            }

        }
    }

    //获取我的追剧
    public static void getMyVideo(Context context, VAMF_recyleview_adapter adapter, int type, String user_id) {
        //协议内容
        Retrofit retrofit = new Retrofit.Builder().baseUrl(uri).client(Client.getClient()).build();
        ApiService apiService =retrofit.create((ApiService.class));
        Call<ResponseBody> call;
        if (user_id.equals("-1"))
        {
            Toast.makeText(context,"未登陆",Toast.LENGTH_SHORT).show();
            return ;
        }
        call = apiService.getmyfollowvideo(user_id);

        //异步请求
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody responseBody =response.body();
                if (responseBody==null){
                    Toast.makeText(context,"内部服务器错误",Toast.LENGTH_SHORT).show();
                    return;
                }
                try {
                    Log.e("onResponse",response.body().toString());
                    //转化json字符串
                    String jsonStr=responseBody.string();
                    System.out.println(jsonStr+"dasdhasydhyaiu");
                    Gson gson= new Gson();
                    ResponsEntity_video ra=gson.fromJson(jsonStr, ResponsEntity_video.class); //把响应数据jsonstr转化为ServiceBobdy实体类
                    if (ra.getCode()==200){
                        //按时间排序
                        Collections.sort(ra.getData(), new Comparator<VideoEntity>() {
                            public int compare(VideoEntity o1, VideoEntity o2) {
                                return o2.getVideo_pub_time().compareTo(o1.getVideo_pub_time());
                            }
                        });
                        //Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                        List<VideoEntity> videoEntities=new ArrayList<>();
                        if (type==0){
                            for (VideoEntity v: ra.getData()){
                                if (v.getVideo_type().equals("综艺")){
                                    videoEntities.add(v);
                                }
                            }
                        }else if (type==1){
                            for (VideoEntity v: ra.getData()){
                                if (v.getVideo_type().equals("动漫")){
                                    videoEntities.add(v);
                                }
                            }
                        }else if (type==2){
                            for (VideoEntity v: ra.getData()){
                                if (v.getVideo_type().equals("电视剧")){
                                    videoEntities.add(v);
                                }
                            }
                        }else if (type==3){
                            for (VideoEntity v: ra.getData()){
                                if (v.getVideo_type().equals("电影")){
                                    videoEntities.add(v);
                                }
                            }
                        }
                        //按时间排序
                        Collections.sort(videoEntities, new Comparator<VideoEntity>() {
                            public int compare(VideoEntity o1, VideoEntity o2) {
                                return o2.getVideo_pub_time().compareTo(o1.getVideo_pub_time());
                            }
                        });
                        adapter.setData(videoEntities);
                    }
                    else {
                        //Toast.makeText(context,ra.getMsg(),Toast.LENGTH_SHORT).show();
                    }

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(context,"网络异常",Toast.LENGTH_SHORT).show();
            }
        });
    }
}
